import type { IResponse } from '@/api/config/types';
import { message, type TableColumnType } from 'ant-design-vue';
import type { LabeledValue } from 'ant-design-vue/es/select';

export interface ColumnProps extends TableColumnType {
  show?: boolean;
}

export const notify = <T = any>(data?: IResponse<T>) => {
  if (!data) {
    message.warn('请求发生问题');
    return;
  }
  if (data.code === 200) {
    return message.success(data.msg);
  } else {
    return message.error(data.msg);
  }
};
export const formatColumns = (columns: ColumnProps[]) => {
  return columns.filter(e => {
    e.ellipsis = true;
    e.key = `${e.dataIndex}`;
    e.align = 'center';
    if (e.show) {
      return e;
    }
  });
};
export const translateOptions = (options: LabeledValue[]) => {
  const { t } = useI18n();
  return options.map(e => {
    e.label = t(e.label);
    return e;
  });
};
